package com.iwayin.core.dao.user;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.iwayin.core.dao.BaseDAOImpl;
import com.iwayin.core.dataobject.UserDO;
import com.iwayin.core.vo.SearchVO;

public class UserDAOImpl extends BaseDAOImpl implements UserDAO {

	@Override
	public Long addUser(UserDO user) {
		return (Long) executeInsert("UserDAO.addUser", user);
	}

	@Override
	public UserDO getUserById(Long userId) {
		return (UserDO) queryForObject("UserDAO.getUserById", userId);
	}

	@Override
	public UserDO getUserByLoginName(String loginName) {
		return (UserDO) queryForObject("UserDAO.getUserByLoginName", loginName);
	}
	
	@Override
	public UserDO getUserByNickName(String nickname) {
		return (UserDO) queryForObject("UserDAO.getUserByNickName", nickname);
	}

	@Override
	public Integer updatePassword(UserDO user) {
		return this.getSqlMapClientTemplate().update("UserDAO.updatePassword", user);
	}

	@Override
	public UserDO getUserByEmail(String email) {
		return (UserDO) queryForObject("UserDAO.getUserByEmail", email);
	}

	@Override
	public void fansCountPlusOne(Long userId) {
		this.getSqlMapClientTemplate().update("UserDAO.fansCountPlusOne", userId);
	}

	@Override
	public void fansCountMinusOne(Long userId) {
		this.getSqlMapClientTemplate().update("UserDAO.fansCountMinusOne", userId);
	}

	@Override
	public void followCountPlusOne(Long userId) {
		this.getSqlMapClientTemplate().update("UserDAO.followCountPlusOne", userId);
	}

	@Override
	public void followCountMinusOne(Long userId) {
		this.getSqlMapClientTemplate().update("UserDAO.followCountMinusOne", userId);
	}

	@Override
	public void updateUserInfo(UserDO user) {
		this.getSqlMapClientTemplate().update("UserDAO.updateUserInfo", user);
	}

	@Override
	public void askCountPlusOne(Long userId) {
		this.getSqlMapClientTemplate().update("UserDAO.askCountPlusOne",userId);
	}
	
	@Override
	public void askCountminuOne(Long userId) {
		executeUpdate("UserDAO.askCountminuOne", userId);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<UserDO> listUser(UserDO query) {
		return executeQueryForList("UserDAO.listUser", "UserDAO.listUser.count", query);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<SearchVO> searchUser(SearchVO query) {
		return this.executeQueryForList("UserDAO.searchUser", "UserDAO.searchUser.count",query);
	}
	@Override
	public List<UserDO> findUsers(List<Long> userIds) {
			if(userIds ==null){
				return new ArrayList<UserDO>();
			}
			HashMap<String, Object> params = new HashMap<String, Object>();
			params.put("userIds", userIds);
			return this.queryForList("UserDAO.findUsers", params);
		}
	@Override
	public void answerCountPlusOne(Long userId) {
		this.getSqlMapClientTemplate().update("UserDAO.answerCountPlusOne",userId);
		
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Long> findSystemUsers() {
		return this.getSqlMapClientTemplate().queryForList("UserDAO.findSystemUsers");
	}

	@Override
	public void likeReceivePlusOne(Long userId) {
		executeUpdate("UserDAO.likeReceivePlusOne", userId);
	}
	@Override
	public void updateUserStatus(UserDO user) {
		executeUpdate("UserDAO.updateUserStatus", user);
	}
	@Override
	public void likeReceiveMinusOne(Long userId) {
		executeUpdate("UserDAO.likeReceiveMinusOne", userId);
	}
	
}
	


	
